<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>草场信息管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			mapall();
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		function mapall()
		{
			var reg = new RegExp('"',"g");  
			var str = $("#coordinates").val().replace(reg, "");  
			var json = eval('(' +str + ')'); 
			var polylinePointsArray = [];
			var lat;
			var lon;
			for(var item in json){ 
	            		var x = json[item]["lat"] ;
				    var y =  json[item]["lon"];
				    polylinePointsArray.push( new BMap.Point(y,x)); 
				    if(json[item]["sort"] == 1)
				    {
				    	lat = json[item]["lat"] ;
				    	lon = json[item]["lon"];
				    }
	           
	        } 
			
			var map = new BMap.Map("allmap");    // 创建Map实例  
			map.centerAndZoom(new BMap.Point(lon, lat), 15);  // 初始化地图,设置中心点坐标和地图级别
		 
			
 			map.enableScrollWheelZoom();
 			var polygon = new BMap.Polygon(polylinePointsArray, {strokeColor:"red", strokeWeight:2, strokeOpacity:0.5}); 
 			map.addOverlay(polygon);           //增加多边形
 			/*			map.centerAndZoom(polylinePointsArray[0], 15); 
			polyline = new BMap.Polygon(polylinePointsArray, {strokeColor:"blue", strokeWeight:2, strokeOpacity:0.5})
			map.addOverlay(polyline);  */
		}
		
		
	</script>
	<!-- 百度地图api --> 
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=Q4MPiEDZc7UcG18QEUAqnqf48MyWWdED"></script>
	<script type="text/javascript" src="http://api.map.baidu.com/library/SearchInfoWindow/1.5/src/SearchInfoWindow_min.js"></script>
	<link rel="stylesheet" href="http://api.map.baidu.com/library/SearchInfoWindow/1.5/src/SearchInfoWindow_min.css" />
	
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/grassinfo/userGrasslandInfo/">草场信息列表</a></li>
		<li class="active"><a href="${ctx}/grassinfo/userGrasslandInfo/form?id=${userGrasslandInfo.id}">草场信息<shiro:hasPermission name="grassinfo:userGrasslandInfo:edit">${not empty userGrasslandInfo.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="grassinfo:userGrasslandInfo:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="userGrasslandInfo" action="${ctx}/grassinfo/userGrasslandInfo/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">草场名称：</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="60" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">手输面积：</label>
			<div class="controls">
				<form:input path="area" htmlEscape="false" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">测量面积：</label>
			<div class="controls">
				<form:input path="clArea" htmlEscape="false" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group"  hidden="hidden">
			<label class="control-label">用户：</label>
			<div class="controls">
				<form:input path="userinfo.id" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">草场图片：</label>
			<div class="controls">
				<form:hidden id="grassImg" path="grassImg" htmlEscape="false" maxlength="200" class="input-xlarge"/>
				<sys:ckfinder input="grassImg" type="images" uploadPath="/grassinfo/userGrasslandInfo" selectMultiple="true"/>
			</div>
		</div>
		<div class="control-group" hidden="hidden">
			<label class="control-label">草场经纬度(多个点)json格式：</label>
			<div class="controls">
				<form:input path="coordinates" htmlEscape="false" maxlength="500" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">草场经纬度：</label>
			<div  id="allmap"  style="width:700px;height:500px" class="controls">
			 
			</div>
		</div>
		
			
		</div>
		<div class="control-group">
			<label class="control-label">备注：</label>
			<div class="controls">
				<form:input path="remark" htmlEscape="false" maxlength="100" class="input-xlarge "/>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="grassinfo:userGrasslandInfo:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>